package com.crm.business.crm.controller;


import cn.hutool.core.util.StrUtil;
import com.crm.business.crm.service.CrmLargeScreenSettingService;
import com.crm.common.crm.entity.BO.CrmLargeScreenSettingBO;
import com.crm.common.crm.entity.BO.CrmLargeScreenSettingSaveBO;
import com.crm.common.crm.entity.BO.CrmLargeScreenSettingSearchBO;
import com.crm.common.ka.core.common.R;
import com.crm.common.ka.core.common.Result;
import com.crm.common.ka.core.entity.BasePage;
import com.crm.common.ka.core.servlet.upload.FileEntity;
import com.crm.common.ka.core.servlet.upload.UploadEntity;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * <p>
 * 线索表 前端控制器
 * </p>
 *
 * @author zhangzhiwei
 * @since 2020-05-21
 */
@RestController
@RequestMapping("/crmLargeScreenSetting")
@Api(tags = "大屏配置接口")
public class CrmLargeScreenSettingController {

    @Autowired
    private CrmLargeScreenSettingService crmLargeScreenSettingService;

    @PostMapping("/queryPageList")
    @ApiOperation("查询列表页数据")
    @ResponseBody
    public Result<BasePage<CrmLargeScreenSettingBO>> queryPageList(@RequestBody CrmLargeScreenSettingSearchBO crmLargeScreenSetting) {
        BasePage<CrmLargeScreenSettingBO> mapBasePage = crmLargeScreenSettingService.queryList(crmLargeScreenSetting);
        return R.ok(mapBasePage);
    }

    @PostMapping("/add")
    @ApiOperation("保存数据")
//    @SysLogHandler(behavior = BehaviorEnum.SAVE,object = "新增了ROI投放金额",detail = "新增了ROI投放金额")
    public Result add(@RequestBody CrmLargeScreenSettingSaveBO crmModel) {
        crmLargeScreenSettingService.addOrUpdate(crmModel);
        return R.ok();
    }

    @PostMapping("/update")
    @ApiOperation("修改数据")
//    @SysLogHandler(behavior = BehaviorEnum.UPDATE)
    public Result update(@RequestBody CrmLargeScreenSettingSaveBO crmModel) {
        crmLargeScreenSettingService.addOrUpdate(crmModel);
        return R.ok();
    }

    /**
     * 上传
     * @param file
     * @param batchId
     * @param type
     * @param isPublic
     * @return
     * @throws IOException
     */
    @PostMapping("/upload")
    @ApiOperation("上传文件")
    public Result<UploadEntity> upload(@RequestParam("file")
                                       @ApiParam("文件") MultipartFile file,
                                       @ApiParam("batchId") String batchId,
                                       @ApiParam("文件类型") String type,
                                       @RequestParam(value = "isPublic",required = false) String isPublic) throws IOException {
        if (StrUtil.isEmpty(isPublic)){
            isPublic = "0";
        }
        UploadEntity entity = crmLargeScreenSettingService.upload(file, batchId, type,isPublic);
        return Result.ok(entity);
    }

    @PostMapping("/updateLargeScreenSettingDataStatus")
    @ApiOperation("修改大屏配置状态")
    public Result updateLargeScreenSettingDataStatus(@RequestParam("checkStatus") String checkStatus, @RequestParam("batchId") String batchId) {
        crmLargeScreenSettingService.updateLargeScreenSettingDataStatus(checkStatus,batchId);
        return R.ok();
    }

    /**
     * 查询启用的视频数据
     * @return
     */
    @PostMapping("/queryMp4")
    @ApiOperation("上传文件")
    @ResponseBody
    public Result<FileEntity> queryMp4(){
        FileEntity fileEntityList = crmLargeScreenSettingService.queryMp4();
        return Result.ok(fileEntityList);
    }

    @PostMapping("/deleteMp4")
    @ApiOperation("删除文件")
    public Result deleteMp4(@RequestBody List<Integer> fileId){

        crmLargeScreenSettingService.deleteMp4(fileId);
        return Result.ok();
    }
}

